package com.jkl.databaseserver.Config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    //消费者队列名称常量
    public static final String QUEUE_INSERT = "insert";
    public static final String QUEUE_UPDATE = "update";
    public static final String QUEUE_DELETE= "delete";
    public static final String QUEUE_SEND="send";
    public static final String QUEUE_AGREE="agree";
    //消费者交换机名称常量
    public static final String EXCHANGE_CON = "routing_exchange";


    /**
     * 声明队列 Queue
     */
    @Bean
    public Queue queue1() {
        return new Queue(QUEUE_INSERT, true, false, false, null);
    }
    @Bean
    public Queue queue2() {
        return new Queue(QUEUE_UPDATE , true, false, false, null);
    }
    @Bean
    public Queue queue3() {
        return new Queue(QUEUE_DELETE , true, false, false, null);
    }
    @Bean
    public Queue queue4(){return new Queue(QUEUE_SEND,true,false,false,null);}
    @Bean
    public Queue queue5(){return new Queue(QUEUE_AGREE,true,false,false,null);}

    /**
     * 声明direct交换机
     */
    @Bean
    DirectExchange directExchange() {
        return new DirectExchange(EXCHANGE_CON ,true,false,null);
    }

    /**
     * 交换机队列绑定
     */
    @Bean
    Binding bindingExchange1() {
        return BindingBuilder.bind(queue1()).to(directExchange()).with("insert");
    }

    @Bean
    Binding bindingExchange2() {
        return BindingBuilder.bind(queue2()).to(directExchange()).with("update");
    }

    @Bean
    Binding bindingExchange3() {
        return BindingBuilder.bind(queue3()).to(directExchange()).with("delete");
    }
    @Bean
    Binding bindingExchange4() {
        return BindingBuilder.bind(queue4()).to(directExchange()).with("send");
    }
    @Bean
    Binding bindingExchange5() {
        return BindingBuilder.bind(queue5()).to(directExchange()).with("agree");
    }
}
